<?php

/**
 * @author nguyenbinh
 * @copyright 2012
 */
 
 
defined('DSVH') or die('Restricted access');
 
//add chuc danh
function insertgiaoan($local){
    mysql_query("insert giao_an set ten_giao_an = '".$local['ten_giao_an']."',
    file = '".$local['file']."',
    link = '".$local['link']."',
    tac_gia = '".$local['tac_gia']."',
    can_bo_id = '".$_SESSION['can_bo_id']."',
    dung_luong = '".$local['dung_luong']."',
    khoi_hoc_id = '".$local['khoi_hoc_id']."',
    nhom_giao_an_id = '".$local['nhom_giao_an_id']."',
    general = '".$local['mo_ta_chung']."',
    add_date = NOW(),
    detail = '".$local['mo_ta_chi_tiet']."'", 
    dbconnect());
}
//list chuc danh
function getListgiaoan($start,$limit)
    {
        $local_list = mysql_query("SELECT * FROM giao_an
        left join can_bo ON giao_an.can_bo_id = can_bo.can_bo_id
       
        order by giao_an_id desc LIMIT ".(int)$start.",".(int)$limit."
        ", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }

function getListgiaoan1($start,$limit)
    {
        $local_list = mysql_query("SELECT * FROM giao_an
        left join can_bo ON giao_an.can_bo_id = can_bo.can_bo_id
        left join khoi_hoc ON khoi_hoc.khoi_hoc_id = giao_an.khoi_hoc_id
        left join nhom_giao_an ON nhom_giao_an.nhom_giao_an_id = giao_an.nhom_giao_an_id
        order by giao_an_id desc LIMIT ".(int)$start.",".(int)$limit."
        ", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }
    
//ham lay du lieu phong ban theo id
function getgiaoan($id)
    {
    $pro = mysql_query("select * from giao_an where giao_an_id = '".(int)$id."'", dbconnect());
    return mysql_fetch_array($pro);
    }
    
//cap nhat trong muc sua
function editgiaoan($id, $local)
{
    mysql_query("update giao_an set ten_giao_an ='".$local['ten_giao_an']."',
    file = '".$local['file']."',
    link = '".$local['link']."',
    tac_gia = '".$local['tac_gia']."',
    general = '".$local['mo_ta_chung']."',
    dung_luong = '".$local['dung_luong']."',
    khoi_hoc_id = '".$local['khoi_hoc_id']."',
    nhom_giao_an_id = '".$local['nhom_giao_an_id']."',
    last_edit = NOW(),
    detail = '".$local['mo_ta_chi_tiet']."'
    where giao_an_id = '".(int)$id."'", dbconnect());
}

// xoa thu muc
function delgiaoan($id){
    mysql_query("delete from giao_an where giao_an_id ='".(int)$id."'", dbconnect());
}

function listKhoiHoc()
    {
        $local_list = mysql_query("SELECT * FROM khoi_hoc
        ", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }

function listNhomGiaoAn()
    {
        $local_list = mysql_query("SELECT * FROM nhom_giao_an
        ", dbconnect());
        $result = array();
        while ($local = mysql_fetch_array($local_list)){
            $result []= $local;
        }
        return $result;
    }

 function checkcanbo($param){
    $sql = "SELECT * FROM can_bo where giao_an_id = '".escape($param)."'";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
}

function check_hoso_pvt($param){
    $sql = "SELECT * FROM ho_so_phi_vat_the where giao_an_id = '".escape($param)."'";
    $result = mysql_query($sql, dbconnect());
    return mysql_num_rows($result);
}

function total(){
   $result = mysql_query("select * from giao_an",dbconnect());
    return mysql_num_rows($result);
}

?>